package com.huike.controller;

import com.huike.core.controller.BaseController;
import com.huike.core.domain.AjaxResult;
import com.huike.dto.ClueDto;
import com.huike.dto.ClueFalseDto;
import com.huike.dto.GainClueDto;
import com.huike.result.MyPageResult;
import com.huike.result.PageResult;
import com.huike.service.ClueService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/clues/clue")
@Slf4j
public class ClueController extends BaseController {

    @Autowired
    private ClueService clueService;

    /**
     * 分页查询线索
     * @param clueDto
     * @return
     */
    @GetMapping("/list")
    public MyPageResult getClueListPage(ClueDto clueDto ) {
        log.info("分页查询线索，{}",clueDto);
        PageResult clueListPage = clueService.getClueListPage(clueDto);
        return MyPageResult.ok(clueListPage.getRecords(),clueListPage.getTotal());
    }

    /**
     * 新增线索
     * @param clueDto
     * @return
     */
    @PostMapping
    public AjaxResult addClue(@RequestBody ClueDto clueDto ) {
        log.info("新增线索，{}",clueDto);
        clueService.addClue(clueDto);
        return success();
    }
    /**
     * 通过id查看线
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public AjaxResult getClueById(@PathVariable Integer id ) {
        log.info("通过id查看线索，{}",id);
        return success(clueService.getClueById(id));
    }
    /**
     * 转成伪线索
     * @param id
     * @return
     */
    @PutMapping("/false/{id}")
    public AjaxResult updateClueFalseById(@PathVariable Integer id ,@RequestBody ClueFalseDto clueFalseDto ) {
        log.info("转成伪线索，{},{}",id,clueFalseDto);
        clueService.updateClueFalseById(id,clueFalseDto);
        return success();
    }
    /**
     * 批量捞取
     * @param gainClueDto
     * @return
     */
    @PutMapping("/gain")
    public AjaxResult gainClueByIds(@RequestBody GainClueDto gainClueDto ) {
        log.info("批量捞取，{}",gainClueDto);
        clueService.gainClueByIds(gainClueDto);
        return success();
    }
    /**
     * 批量分配线索
     * @param gainClueDto
     * @return
     */
    @PutMapping("/assignment")
    public AjaxResult assignmentClueByIds(@RequestBody GainClueDto gainClueDto ) {
        log.info("批量分配线索，{}",gainClueDto);
        clueService.assignmentClueByIds(gainClueDto);
        return success();
    }
    /**
     * 转商机
     * @param id
     * @return
     */
    @PutMapping("/changeBusiness/{id}")
    public AjaxResult changeBusiness(@PathVariable Integer id  ) {
        log.info("批量分配线索，{}",id);
        clueService.changeBusiness(id);
        return success();
    }
}
